<?php
/**
 * TomatoCMS
 *
 * LICENSE
 *
 * This source file is subject to the GNU GENERAL PUBLIC LICENSE Version 2
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://www.gnu.org/licenses/gpl-2.0.txt
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@tomatocms.com so we can send you a copy immediately.
 *
 * @copyright    Copyright (c) 2009-2010 TIG Corporation (http://www.tig.vn)
 * @license        http://www.gnu.org/licenses/gpl-2.0.txt GNU GENERAL PUBLIC LICENSE Version 2
 * @version     $Id: list.phtml 3287 2010-06-04 09:37:56Z huuphuoc $
 */
?>
<?php
$this->headTitle($this->translator('attribute_list_page_title'));

$this->headLink()
    ->appendStylesheet($this->APP_STATIC_SERVER.'/js/jquery.ui/themes/base/ui.core.css')
    ->appendStylesheet($this->APP_STATIC_SERVER.'/js/jquery.ui/themes/base/ui.resizable.css')
    ->appendStylesheet($this->APP_STATIC_SERVER.'/js/jquery.ui/themes/base/ui.dialog.css')
    ->appendStylesheet($this->APP_STATIC_SERVER.'/js/jquery.ui/themes/base/ui.theme.css');

$this->headScript()
    ->appendFile($this->APP_STATIC_SERVER.'/js/jquery.ui/ui.core.js')
    ->appendFile($this->APP_STATIC_SERVER.'/js/jquery.ui/ui.draggable.js')
    ->appendFile($this->APP_STATIC_SERVER.'/js/jquery.ui/ui.droppable.js')
    ->appendFile($this->APP_STATIC_SERVER.'/js/jquery.ui/ui.resizable.js')
    ->appendFile($this->APP_STATIC_SERVER.'/js/jquery.ui/ui.dialog.js');
?>

<div class="grid_12 t_a_ui_breadcrumb">
    <span><?php echo $this->translator('attribute_list_breadcump'); ?></span>
</div>

<div class="grid_12 t_a_bottom">
    <div class="grid_9 alpha"><?php echo $this->translator('attribute_list_guide'); ?></div>

    <div class="grid_3 omega">
        <div class="t_a_right">
            <a href="<?php echo $this->url(array(), 'attribute_attribute_add'); ?>" class="t_a_ui_button_link"><span><?php echo $this->translator('attribute_add_breadcump'); ?></span></a>
        </div>
    </div>
</div>

<!-- Search form -->
<form method="POST" action="<?php echo $this->url(array(), 'attribute_attribute_list'); ?>" id="frmAttributeSearch">
<div class="grid_12 t_a_bottom">
    <div class="prefix_1 suffix_1">
        <div class="clearfix t_a_bottom">
            <div class="grid_5 alpha">
                <label><?php echo $this->translator('attribute_type_admin_name'); ?>:</label>
                <input type="text" style="width: 180px" name="attribute_type_admin_name" id="attribute_type_admin_name" value="<?php if (isset($this->exp['attribute_type_admin_name'])) : ?><?php echo $this->exp['attribute_type_admin_name']; ?><?php endif; ?>" />
            </div>

            <div class="grid_5 omega">
                <label><?php echo $this->translator('attribute_category_name'); ?>:</label>
                <select name="category_id" style="width: 170px">
                    <option value="">---</option>
                    <?php for ($i = 0; $i < count($this->categories); $i++) : ?>
                    <option value="<?php echo $this->categories[$i]->category_id; ?>"<?php if (isset($this->exp['category_id']) && $this->exp['category_id'] == $this->categories[$i]->category_id) : ?> selected="selected"<?php endif; ?>><?php echo str_repeat('---', $this->categories[$i]->depth).$this->categories[$i]->category_admin_name; ?></option>
                    <?php endfor; ?>
                </select>
            </div>
        </div>

        <hr />

        <div class="clearfix t_a_bottom">
            <label>&nbsp;</label>
            <button type="submit"><span><?php echo $this->translator('attribute_list_search_button'); ?></span></button>
        </div>
    </div>
</div>
</form>
<!--end search form-->

<!-- List of attribute -->
<?php if ($this->numAttribute == 0) : ?>
<div class="grid_12 t_a_bottom">
    <?php echo $this->translator('attribute_list_not_found'); ?>
</div>
<?php else : ?>
<div class="grid_12 t_a_ui_data_list_header">
    <div class="grid_4 alpha">
        <div><input type="checkbox" id="checkAll" /> <?php echo $this->translator('attribute_type_admin_name'); ?></div>
    </div>
    <div class="grid_3"><?php echo $this->translator('attribute_category_name'); ?></div>
    <div class="grid_3"><?php echo $this->translator('attribute_type_content_name'); ?></div>
    <div class="grid_2 omega"><?php echo $this->translator('attribute_id'); ?></div>
</div>

<div class="grid_12 t_a_bottom" id="attribute">
    <?php foreach ($this->attributes as $attribute) : ?>
    <div id="attributeRow_<?php echo $attribute->attribute_type_id; ?>" class="clearfix t_a_ui_data_list_content">

        <div class="grid_4 alpha">
            <div>
                <input type="checkbox" class="selectEnterprise" value="<?php echo $attribute->attribute_type_id; ?>" />
                <a href="<?php echo $this->url(array('attribute_id' => $attribute->attribute_type_id), 'attribute_attribute_edit'); ?>"><?php echo $attribute->attribute_type_admin_name; ?></a>
            </div>

            <div class="t_a_top t_a_ui_helper_action">
                <?php if ($this->allow('edit')) : ?>
                <a href="<?php echo $this->url(array('attribute_id' => $attribute->attribute_type_id), 'attribute_attribute_edit'); ?>"><?php echo $this->translator('attribute_list_action_edit'); ?></a>
                <?php endif; ?>
                <?php if ($this->allow('delete')) : ?>
                 | <a class="deleteAction" rel="<?php echo $attribute->attribute_type_id; ?>" href="javascript: void(0);"><?php echo $this->translator('attribute_list_action_delete'); ?></a>
                <?php endif; ?>
            </div>
        </div>

        <div class="grid_3">
            <?php echo $this->arrCategory[$attribute->attribute_type_id];?>
        </div>
        <div class="grid_3">
            <?php echo (isset($this->arrAttributeType[$attribute->attribute_type_id]))?$this->arrAttributeType[$attribute->attribute_type_id]:'-';?>
        </div>
        <div class="grid_2 omega"><?php echo $attribute->attribute_type_id; ?></div>
    </div>
    <?php endforeach; ?>
</div>
<div class="grid_12 t_a_bottom t_a_paginator">
    <?php echo $this->paginator()->slide($this->paginator, $this->paginatorOptions);?>
</div>
<?php endif;?>

<div id="messageDialog"></div>
<div id="confirmDialog"></div>

<script type="text/javascript">
$(document).ready(function() {

    <?php if ($this->allow('delete')) : ?>
    $('a.deleteAction').click(function() {
        var self = this;
        $('#confirmDialog').html('<?php echo addslashes($this->translator('attribute_list_action_delete_confirm')); ?>')
            .dialog({
                title: '<?php echo addslashes($this->translator('common_dialog_confirm')); ?>',
                dialogClass: 't_a_ui_dialog',
                modal: true,
                closeOnEscape: false,
                resizable: false,
                open: function(event, ui) {
                    $('.ui-dialog-titlebar-close').hide();
                    $(this).parent().find('.ui-dialog-buttonpane button').wrapInner('<span/>');
                },
                buttons: {
                    '<?php echo addslashes($this->translator('common_dialog_confirm_no')); ?>': function() {
                        $(this).dialog('destroy');
                    },
                    '<?php echo addslashes($this->translator('common_dialog_confirm_yes')); ?>': function() {
                        $(this).dialog('destroy');
                        $(self).html('').addClass('t_a_ui_helper_loading');
                        var id = $(self).attr('rel');
                        $.ajaxq('attribute', {
                            type: 'POST',
                            url: "<?php echo $this->url(array(), 'attribute_attribute_delete'); ?>",
                            data: { id: id },
                            success: function(response) {
                                if ('RESULT_OK' == response) {
                                    $('#attributeRow_' + id).fadeOut('slow');
                                }
                                /*else
                                {
                                    $(id_delete).html('<span style="color:red"><?php echo $this->translator('attribute_list_action_not_deleteable'); ?></span>').removeClass('t_a_link t_a_loading');
                                }*/
                                else if('RESULT_IS_USED' == response) {
                                    $(self).removeClass('t_a_ui_helper_loading').append($('<span/>').html('<?php echo addslashes($this->translator('attribute_list_action_delete')); ?>'));
                                    $('#messageDialog').html('<?php echo addslashes($this->translator('attribute_list_action_not_deleteable')); ?>')
                                    .dialog({
                                        title: '<?php echo addslashes($this->translator('common_dialog_message')); ?>',
                                        dialogClass: 't_a_ui_dialog',
                                        modal: true,
                                        show: { effect: 'fade' },
                                        open: function(event, ui) {
                                            setTimeout(function() {
                                                $('#' + event.target.id).dialog('option', 'hide', 'fade').dialog('destroy');
                                            }, 3000);
                                        }
                                    });
                                }

                            }
                        });
                    }
                }
            });
    });
    <?php endif; ?>
});
</script>
